/**
 * 添加或者修改页面
 */
var ProductWarningInfoInfoDlg = {
    data: {
        id: "",
        orgId: "",
        orgName: "",
        productId: "",
        productName: "",
        shopId: "",
        countType: "",
        lessWarningValue: "",
        sendAmount: "",
        remark: "",
        createTime: "",
        createUser: "",
        updateTime: "",
        updateUser: "",
        isDelete: ""
    }
};

layui.use(['form', 'admin', 'ax','laydate','upload','formSelects'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;

    // var typeName = $('#typeName').val();

    $.ajax({
        url: '/baseCommonSelect/getFactoryNumList',
        dataType: 'json',
        type: 'post',
        success: function(data) {
            if (data!== null) {
                $("#orgNameSelect").empty();
                $("#orgNameSelect").append(new Option());
                $.each(data, function(index, item) {
                    $('#orgNameSelect').append(new Option(item.value,item.id));
                });
            } else {
                $("#orgNameSelect").append(new Option("暂无数据", ""));
            }
            //重新渲染
            form.render("select");
        }
    });

    //监听供应商的下拉框事件
    form.on('select(orgNameSelect)', function(data){
        var supplierId = data.value;
        $.ajax({
            url: '/baseCommonSelect/getProductList',
            dataType: 'json',
            data: {supplierId: supplierId},
            type: 'post',
            success: function(data) {
                if (data!== null) {
                    $("#productNameSelect").empty();
                    $("#productNameSelect").append(new Option());
                    $.each(data, function(index, item) {
                        $('#productNameSelect').append(new Option(item.value,item.id));
                    });
                } else {
                    $("#productNameSelect").append(new Option("暂无数据", ""));
                }
                //重新渲染
                form.render("select");
            }
        });

    });


    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        //获取选中的值
        var orgId = $("#orgNameSelect").val();
        //获取选中文本
        var orgName = $("#orgNameSelect").find("option:selected").text();

        //获取选中的值
        var productId = $("#productNameSelect").val();
        //获取选中文本
        var productName = $("#productNameSelect").find("option:selected").text();

        data.field.orgId = orgId;
        data.field.orgName = orgName;

        data.field.productId = productId;
        data.field.productName = productName;
        var ajax = new $ax(Feng.ctxPath + "/productWarningInfo/addItem", function (data) {
            Feng.success("添加成功！");
            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);
            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });


});